//
//  ByBlueToothMeatureH1Model.m
//  laserdevice_ios
//
//  Created by pro on 17/2/14.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByBlueToothMeaturesH1Model.h"

@implementation ByBlueToothMeaturesH1Model

- (instancetype)initWithDataHexString:(NSString *)hexStr {
    
    if (self = [super initWithDataHexString:hexStr]) {
        
        self.name = [NSString stringWithFormat:@"H1%@", STRING(@"moxing")];
        
        NSString *angleStr = [hexStr substringWithRange:NSMakeRange(42, 18)];
        self.angle = [[self getNumberFromHexStr:angleStr] floatValue];
        NSString *lengthStr1 = [hexStr substringWithRange:NSMakeRange(70, 18)];
        self.length1 = [[self getNumberFromHexStr:lengthStr1] floatValue];
        NSString *lengthStr2 = [hexStr substringWithRange:NSMakeRange(98, 18)];
        self.length2 = [[self getNumberFromHexStr:lengthStr2] floatValue];
        NSString *lengthStr3 = [hexStr substringWithRange:NSMakeRange(126, 18)];
        self.length3 = [[self getNumberFromHexStr:lengthStr3] floatValue];
        
//        NSLog(@"%li,%.2f,%.2f,%.2f,%.2f", self.numOfData, self.hypotenuseLength, self.horizontalLength, self.verticalLength, self.angle);
    }
    return self;
}

- (instancetype)initWithJsonDic:(NSDictionary *)jsonDic {
    
    if (self = [super initWithJsonDic:jsonDic]) {
        
        NSArray *attributes = jsonDic[@"attributes"];
        self.angle = [attributes[0] floatValue];
        self.length1 = [attributes[1] floatValue];
        self.length2 = [attributes[2] floatValue];
        self.length3 = [attributes[3] floatValue];
    }
    return self;
}


- (NSDictionary *)saveDic {
    
    NSArray *attributes = @[[NSString stringWithFormat:@"%.3lf", self.angle],
                            [NSString stringWithFormat:@"%.6lf", self.length1],
                            [NSString stringWithFormat:@"%.6lf", self.length2],
                            [NSString stringWithFormat:@"%.6lf", self.length3],];
    return @{@"name"        :self.name,
             @"attributes"  :attributes,};
}

- (NSString *)angleStr {
    
    return [NSString stringWithFormat:@"%.1f", self.angle];
}
- (NSString *)length1Str {
    
    return [self getStringFromLength:self.length1];
}
- (NSString *)length2Str {
    
    return [self getStringFromLength:self.length2];
}
- (NSString *)length3Str {
    
    return [self getStringFromLength:self.length3];
}

@end
